<template>
  <!-- 工单表表单弹窗 -->
  <el-dialog
    v-model="visibleDialog"
    :title="props.title"
    width="70%"
    draggable
    @close="closeDialog"
  >
    <el-card shadow="never" class="table-container">
      <div class="formTable2">
        <el-table
          max-height="700"
          ref="dataTableRef"
          v-loading="loading"
          :data="tableData"
          highlight-current-row
          border
        >
          <el-table-column
            type="index"
            label="序号"
            align="center"
            width="100"
          />
          <el-table-column
            label="冷铁名称"
            prop="materialCode"
            min-width="200"
            show-overflow-tooltip
          />
          <el-table-column
            label="数量"
            prop="productQuantity"
            min-width="100"
            show-overflow-tooltip
            align="right"
          />
          <el-table-column
            label="日期"
            prop="completeTime"
            min-width="100"
            show-overflow-tooltip
            align="center"
          />
          <el-table-column
            label="操作者"
            prop="lastUpdatedUserName"
            min-width="200"
            show-overflow-tooltip
          />
        </el-table>
        <el-pagination
          :background="true"
          :current-page="pageable.pageNum"
          :page-size="pageable.pageSize"
          :page-sizes="[10, 25, 50, 100]"
          :total="pageable.total"
          layout="total, sizes, prev, pager, next, jumper"
          class="mt-[20px]"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </el-card>

    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeDialog">关 闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { useTable, useDownload, useDictionary } from "@/utils/useTable";
import request from "@/utils/request";

defineOptions({
  name: "MESPLANWORKINGFORMIRONUPDATE",
  inheritAttrs: false,
});

const props = defineProps({
  visible: {
    type: Boolean,
    default: () => {
      return false;
    },
  },
  title: {
    type: String,
    default: () => {
      return "";
    },
  },
  data: {
    type: Object,
    default: () => {
      return {};
    },
  },
});

const emit = defineEmits(["reset-table", "change-visible", "select-row"]);

const disabledDate = (time: Date) => {
  return time.getTime() <= Date.now() - 8.64e7;
};

// 请求参数
const requestApi = "/mes/mesproducereportrecord/queryByPage";

// 是否需要分页
const pagination = true;

const initParam = {};

// 初始化搜索参数数据
const searchParamInit = {
  workingFormId: "",
};

const deleteParam = {
  api: "/srm/srmplanschedulelog/delete",
  data: {},
};

// 数据请求错误后处理
function requestError() {}

const dataCallBack = ref(undefined); // 无需二次数据处理&不传赞数也行

// 表格操作 Hooks
const {
  tableData,
  pageable,
  searchParam,
  ids,
  getTableList,
  search,
  reset,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  handleTableDelete,
  loading,
}: any = useTable(
  requestApi,
  initParam,
  searchParamInit,
  pagination,
  dataCallBack.value,
  requestError,
  deleteParam
);

onMounted(() => {
  getTableList();
});

const visibleDialog = ref(false);
watch(
  () => props.visible,
  (newVal: boolean) => {
    visibleDialog.value = newVal;
    if (newVal) {
      // getTableList();
    }
  }
);

watch(
  () => props.data,
  (newVal: any) => {
    if (newVal?.id) {
      const { id } = newVal;
      searchParam.value.workingFormId = id;
      getTableList();
    }
  }
);

/** 重置表单 */
function resetForm() {
  searchParam.printState = "";
}

/** 关闭表单弹窗 */
function closeDialog() {
  visibleDialog.value = false;
  emit("change-visible", false);
  resetForm();
}
// 组件销毁时调用
onBeforeUnmount(() => {
  visibleDialog.value = false;
  emit("change-visible", false);
});
</script>
